13. Exercise: Implement touchStart()

22 14 AAK TouchStart SC V2

Android Developer Documentation

Exercise

In this exercise you are going to implement touchStart().

  1. At the class level, add variables to cache the latest x and y values. After the user stops moving and lifts their touch, these are the starting point for the next path (the next segment of the line to draw).
private var currentX = 0f
private var currentY = 0f
  1. Implement the touchStart() method as follows. Reset the path, move to the x-y coordinates of the touch event (motionTouchEventX and motionTouchEventY) and assign currentX and currentY to that value.
private fun touchStart() {
   path.reset()
   path.moveTo(motionTouchEventX, motionTouchEventY)
   currentX = motionTouchEventX
   currentY = motionTouchEventY
}